package com.ruoyi.lnb.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lnb.domain.Workers;
import com.ruoyi.lnb.service.IWorkersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工作者账号管理Controller
 * 
 * @author lnb
 * @date 2022-04-05
 */
@RestController
@RequestMapping("/lnb/workers")
public class WorkersController extends BaseController
{
    @Autowired
    private IWorkersService workersService;

    /**
     * 查询工作者账号管理列表
     */
    @PreAuthorize("@ss.hasPermi('lnb:workers:list')")
    @GetMapping("/list")
    public TableDataInfo list(Workers workers)
    {
        startPage();
        List<Workers> list = workersService.selectWorkersList(workers);
        return getDataTable(list);
    }

    /**
     * 导出工作者账号管理列表
     */
    @PreAuthorize("@ss.hasPermi('lnb:workers:export')")
    @Log(title = "工作者账号管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Workers workers)
    {
        List<Workers> list = workersService.selectWorkersList(workers);
        ExcelUtil<Workers> util = new ExcelUtil<Workers>(Workers.class);
        util.exportExcel(response, list, "工作者账号管理数据");
    }

    /**
     * 获取工作者账号管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('lnb:workers:query')")
    @GetMapping(value = "/{wusername}")
    public AjaxResult getInfo(@PathVariable("wusername") String wusername)
    {
        return AjaxResult.success(workersService.selectWorkersByWusername(wusername));
    }

    /**
     * 新增工作者账号管理
     */
    @PreAuthorize("@ss.hasPermi('lnb:workers:add')")
    @Log(title = "工作者账号管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Workers workers)
    {
        return toAjax(workersService.insertWorkers(workers));
    }

    /**
     * 修改工作者账号管理
     */
    @PreAuthorize("@ss.hasPermi('lnb:workers:edit')")
    @Log(title = "工作者账号管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Workers workers)
    {
        return toAjax(workersService.updateWorkers(workers));
    }

    /**
     * 删除工作者账号管理
     */
    @PreAuthorize("@ss.hasPermi('lnb:workers:remove')")
    @Log(title = "工作者账号管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{wusernames}")
    public AjaxResult remove(@PathVariable String[] wusernames)
    {
        return toAjax(workersService.deleteWorkersByWusernames(wusernames));
    }
}
